import request from '@/utils/request'
import uploadRequest from '@/utils/uploadRequest'

/**
 *
 * @param method 要访问的方法名称
 * @param data 传输到后台的数据
 * @constructor
 */
export function VSEApi(url, data, isLoading) {
  return request({
    url: url,
    data: data,
    isLoading: typeof isLoading =='undefined' ? true : isLoading
  });
}

export function UPLOADAPI(url, data){
  return uploadRequest({
    url: url,
    data: data
  });
}

export function GetAllBrand(that, callback){
  let params = {
    fieldtypeid: 21
  };
  VSEApi(
    'docsManager/getFieldValueList', params
  ).then((response) => {
    let data = response.data;
    var deviceBrand = {};

    for(var i=0;i<data.length;i++){
      let temp = data[i];
      if(typeof temp.fieldkey == 'undefined' || temp.fieldkey == ''){
        continue;
      }
      deviceBrand[temp.fieldkey] = {
        value: temp.fieldkey,
        label: temp.fieldval
      };
    }

    callback(deviceBrand);
  }).catch((error)=>{
    console.log(that.$t('common.getBrandError'));
    callback({});
  });
}
